import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/apis/common.dart';
import 'package:qgchat/http/models/resModel.dart';
import 'package:qgchat/page/my/myDynamic/BloC/myDynamicBloC.dart';

/// 
/// 删除动态按钮
/// 
class DelBtn extends StatelessWidget {
  const DelBtn(this.id, {Key key}) : super(key: key);

  final int id; // 动态id

  @override
  Widget build(BuildContext context) {
    return Container(
      child: IconButton(
        onPressed: () {
          showCupertinoModalPopup(
            context: context,
            builder: (BuildContext ctx) {
              return CupertinoActionSheet(
                title: Text(
                  "是否删除本条动态",
                  style: TextStyle(
                    fontSize: px(26),
                  ),
                ),
                cancelButton: CupertinoActionSheetAction(
                  onPressed: () => Navigator.pop(ctx),
                  child: Text("取消"),
                ),
                actions: <Widget>[
                  CupertinoActionSheetAction(
                    onPressed: () => del(ctx, context),
                    child: Text(
                      "删除动态",
                      style: TextStyle(
                        color: col("fc3d39"),
                        fontSize: px(40),
                      ),
                    ),
                  )
                ],
              );
            },
          );
        },
        padding: EdgeInsets.zero,
        icon: Image.asset(
          "assets/images/icon/cha.png",
          color: col("bfc2cc"),
          width: px(24),
          height: px(24),
        ),
      ),
    );
  }

  /// 删除方法
  del(ctx, context) async {
    Navigator.pop(ctx);
    ResModel res = await CommonApis.delsenddongtai(id);
    if (res.status == 1) {
      showToast("删除成功");
      BlocProvider.of<MyDynamicBloc>(context).add(MyDynamicEvent.refresh);
    }
  }
}
